#pragma once

#include <iostream>
#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/async.h>
#include <memory>

/*
    mode == true ：发布模式
    mode == false : 调式模式
*/
std::shared_ptr<spdlog::logger> logger;
void InitLog(bool mode, const std::string filename = "", int level = 0)
{
    if(mode == false)
    {
        logger = spdlog::stdout_color_mt("sync_log");
    }
    else
    {
        logger = spdlog::basic_logger_mt("sync_log",filename);
    }

    logger->set_level((spdlog::level::level_enum)level);
    logger->flush_on((spdlog::level::level_enum)level);
    logger->set_pattern(" [%l] [%Y-%m-%d %H:%M:%S] %v");
}


#define LOG_DEBUG(format,...)  logger->debug(std::string("[{} : {}] : ") + format, __FILE__ ,__LINE__, ##__VA_ARGS__);
#define LOG_INFO(format,...)  logger->info(std::string("[{} : {}] : ") + format, __FILE__ ,__LINE__, ##__VA_ARGS__);
#define LOG_WARN(format,...)  logger->warn(std::string("[{} : {}] : ") + format, __FILE__ ,__LINE__, ##__VA_ARGS__);
#define LOG_ERROR(format,...)  logger->error(std::string("[{} : {}] : ") + format, __FILE__ ,__LINE__, ##__VA_ARGS__);